package com.xym.manage.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.xym.manage.pojo.ItemCat;
import com.xym.manage.service.ItemCatService;

@RequestMapping(value = "item/cat")
@Controller
public class ItemCatController {

	@Autowired
	private ItemCatService itemCatService;

	/**
	 * 异步请求
	 * 查寻商品类目  通过pid 默认0
	 * 参数  Id   
	 * @param parentId
	 * @return  list
	 */
	@RequestMapping(method = RequestMethod.GET)
	public ResponseEntity<List<ItemCat>> queryItemCat(
			@RequestParam(value = "id", defaultValue = "0") Long parentId) {
		try {
			ItemCat record = new ItemCat();
			record.setParentId(parentId);
			List<ItemCat> itemCats = this.itemCatService.queryListByWhere(record);
			if (itemCats == null || itemCats.isEmpty()) {
				return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
			}
			return ResponseEntity.ok().body(itemCats);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
	}
}
